<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>贷款管理</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/layer/layer.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			/**
			 * @funciton  数据库 ---  编辑页面  .val(str)
			 */
			function toTextarea(str){
				var reg=new RegExp("<br>","g");
				var regSpace=new RegExp("&nbsp;","g");
				str = str.replace(reg,"\n");
				str = str.replace(regSpace," ");
				return str;
			}
			$(".remarks").each(function () {
				$(this).html(toTextarea($(this).text()));
			})

			//设置或取消精品套餐
			$(".set_boutique,.cancer_boutique").click(function(){
				var that=$(this);
				//弹框提醒是否需要推送服务
				if($(this).hasClass("set_boutique")){
					layer.confirm('此操作会将该贷款设置精品套餐，是否在设置精品套餐的同时向app用户推送服务呢？', {
					    btn: ['是','否'], //按钮
					    shade: false //不显示遮罩
					}, function(index){
						var id=that.data("id");
		            	 $.ajax({  
		                       type : "POST",  //提交方式  
		                       url : "${ctx}/sys/loan/loan/setOrCancerBoutique",//路径  
		                       data : {"id":id,"isPush":true},//数据，这里使用的是Json格式进行传输  
		                       success : function(data) {//返回数据根据结果进行相应的处理  
		                            if(data){
		                            	layer.alert("操作成功,",function(){
		                            		window.location.href="${ctx}/sys/loan/loan";
		                            	});
		                            }else{
		                            	layer.alert("操作失败",-1);
		                            }
		                       }  
		                 });
					},function(index){
						var id=that.data("id");
		            	 $.ajax({  
		                       type : "POST",  //提交方式  
		                       url : "${ctx}/sys/loan/loan/setOrCancerBoutique",//路径  
		                       data : {"id":id,"isPush":false},//数据，这里使用的是Json格式进行传输  
		                       success : function(data) {//返回数据根据结果进行相应的处理  
		                            if(data){
		                            	layer.alert("操作成功,",function(){
		                            		window.location.href="${ctx}/sys/loan/loan";
		                            	});
		                            }else{
		                            	layer.alert("操作失败",-1);
		                            }
		                       }  
		                 });
					});
				}else{
					var id=that.data("id");
	            	 $.ajax({  
	                       type : "POST",  //提交方式  
	                       url : "${ctx}/sys/loan/loan/setOrCancerBoutique",//路径  
	                       data : {"id":id},//数据，这里使用的是Json格式进行传输  
	                       success : function(data) {//返回数据根据结果进行相应的处理  
	                            if(data){
	                            	layer.alert("操作成功,",function(){
	                            		window.location.href="${ctx}/sys/loan/loan";
	                            	});
	                            }else{
	                            	layer.alert("操作失败",-1);
	                            }
	                       }  
	                 });
				}
				  
			});
			
			//设置或取消新品推荐
			$(".set_recomend,.cancer_recomend").click(function(){
				var that=$(this);
				//弹框提醒是否需要推送服务
				if($(this).hasClass("set_recomend")){
					layer.confirm('此操作会将该贷款设置为新品推荐，是否在设置新品推荐的同时向app用户推送服务呢？', {
					    btn: ['是','否'], //按钮
					    shade: false //不显示遮罩
					}, function(index){
						var id=that.data("id");
		            	 $.ajax({  
		                       type : "POST",  //提交方式  
		                       url : "${ctx}/sys/loan/loan/setOrCancerRecomend",//路径  
		                       data : {"id":id,"isPush":true},//数据，这里使用的是Json格式进行传输  
		                       success : function(data) {//返回数据根据结果进行相应的处理  
		                            if(data){
		                            	layer.alert("操作成功,",function(){
		                            		window.location.href="${ctx}/sys/loan/loan";
		                            	});
		                            }else{
		                            	layer.alert("操作失败",-1);
		                            }
		                       }  
		                 });
					},function(index){
						var id=that.data("id");
		            	 $.ajax({  
		                       type : "POST",  //提交方式  
		                       url : "${ctx}/sys/loan/loan/setOrCancerRecomend",//路径  
		                       data : {"id":id,"isPush":false},//数据，这里使用的是Json格式进行传输  
		                       success : function(data) {//返回数据根据结果进行相应的处理  
		                            if(data){
		                            	layer.alert("操作成功,",function(){
		                            		window.location.href="${ctx}/sys/loan/loan";
		                            	});
		                            }else{
		                            	layer.alert("操作失败",-1);
		                            }
		                       }  
		                 });
					});
				}else{
					var id=that.data("id");
	            	 $.ajax({  
	                       type : "POST",  //提交方式  
	                       url : "${ctx}/sys/loan/loan/setOrCancerRecomend",//路径  
	                       data : {"id":id},//数据，这里使用的是Json格式进行传输  
	                       success : function(data) {//返回数据根据结果进行相应的处理  
	                            if(data){
	                            	layer.alert("操作成功,",function(){
	                            		window.location.href="${ctx}/sys/loan/loan";
	                            	});
	                            }else{
	                            	layer.alert("操作失败",-1);
	                            }
	                       }  
	                 });
				}
				  
			});
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/loan/loan/">贷款列表</a></li>
		<shiro:hasPermission name="sys:loan:loan:add"><li><a href="${ctx}/sys/loan/loan/form">贷款添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="loan" action="${ctx}/sys/loan/loan/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>贷款名称：</label>
				<form:input path="name" htmlEscape="false" maxlength="255" class="input-medium"/>
			</li>
			<li><label>渠道银行：</label>
				<form:select path="bankId" cssStyle="min-width: 110px;" >
					<option value="">==请选择==</option>
					<form:options items="${banks}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>贷款名称</th>
				<th>所属银行</th>
                <th>地区</th>
				<th>还款方式</th>
				<th>修改时间</th>
				<th>备注信息</th>
				<th>是否是精品套餐</th>
				<th>新品推荐标示</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="loan">
			<tr>
				<td><a href="${ctx}/sys/loan/loan/form?id=${loan.id}">	${loan.name}</a></td>
				<td>${loan.bankName}</td>
				<td>${loan.area}</td>
				<td>${loan.paymentWay}</td>
				<td><fmt:formatDate value="${loan.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<td class="remarks">${loan.remarks}</td>
				<td>
					 <c:choose>
						<c:when test="${empty loan.boutiqueFlag}"><span style="color:red">不是</span></c:when>
						<c:when test="${ loan.boutiqueFlag==true}"><span style="color:green">是</span></c:when>
						<c:when test="${ loan.boutiqueFlag==false}"><span style="color:red">不是</span></c:when>
						<c:otherwise><span style="color:red">不是</span></c:otherwise>
					</c:choose> 
				</td>
				<td>
					 <c:choose>
						<c:when test="${empty loan.recomendFlag}"><span style="color:red">不是</span></c:when>
						<c:when test="${ loan.recomendFlag==true}"><span style="color:green">是</span></c:when>
						<c:when test="${ loan.recomendFlag==false}"><span style="color:red">不是</span></c:when>
						<c:otherwise><span style="color:red">不是</span></c:otherwise>
					</c:choose> 
				</td>
				<td>
					<shiro:hasPermission name="sys:loan:loan:edit">
    				<a href="${ctx}/sys/loan/loan/form?id=${loan.id}">修改</a>
					<a href="${ctx}/sys/loan/loan/delete?id=${loan.id}" onclick="return confirmx('确认要删除该贷款吗？', this.href)">删除</a>
					</shiro:hasPermission>
				<shiro:hasPermission name="sys:loan:loan:addhomeimg"><a href="${ctx}/sys/loan/loan/addHomeImg?id=${loan.id}">添加轮播图</a></shiro:hasPermission>
					<c:choose>
						<c:when test="${empty loan.boutiqueFlag}"><shiro:hasPermission name="sys:loan:loan:setboutique"><span style="color:red"><a href="#" class="set_boutique" data-id="${loan.id}">设置精品套餐</a></span></shiro:hasPermission></c:when>
						<c:when test="${ loan.boutiqueFlag==true}"><shiro:hasPermission name="sys:loan:loan:setboutique"><span style="color:green"><a href="#" class="cancer_boutique" style="color:red" data-id="${loan.id}">取消精品套餐</a></span></shiro:hasPermission></c:when>
						<c:when test="${ loan.boutiqueFlag==false}"><shiro:hasPermission name="sys:loan:loan:setboutique"><span style="color:red"><a href="#" class="set_boutique" data-id="${loan.id}">设置精品套餐</a></span></shiro:hasPermission></c:when>
						<c:otherwise><span style="color:red"><shiro:hasPermission name="sys:loan:loan:setboutique"><a href="#" class="set_boutique" data-id="${loan.id}">设置精品套餐</a></span></shiro:hasPermission></c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${empty loan.recomendFlag}"><shiro:hasPermission name="sys:loan:loan:setrecomend"><span style="color:red"><a href="#" class="set_recomend" data-id="${loan.id}">设置新品推荐</a></span></shiro:hasPermission></c:when>
						<c:when test="${ loan.recomendFlag==true}"><shiro:hasPermission name="sys:loan:loan:setrecomend"><span style="color:green"><a href="#" style="color:red" class="cancer_recomend" data-id="${loan.id}">取消新品推荐</a></span></shiro:hasPermission></c:when>
						<c:when test="${ loan.recomendFlag==false}"><shiro:hasPermission name="sys:loan:loan:setrecomend"><span style="color:red"><a href="#" class="set_recomend" data-id="${loan.id}">设置新品推荐</a></span></shiro:hasPermission></c:when>
						<c:otherwise><shiro:hasPermission name="sys:loan:loan:setrecomend"><span style="color:red"><a href="#" class="set_recomend" data-id="${loan.id}">设置新品推荐</a></span></shiro:hasPermission></c:otherwise>
					</c:choose>
				<shiro:hasPermission name="sys:loan:loan:setmaterial">
					<a href="${ctx}/sys/loan/loan/material?id=${loan.id}">贷款资料</a>
				</shiro:hasPermission>
					<shiro:hasPermission name="sys:loan:loan:settags">
						<a href="${ctx}/sys/loan/loan/tags?id=${loan.id}">贷款标签</a>
					</shiro:hasPermission>
				<shiro:hasPermission name="sys:loan:loan:setmanager">
					<a href="${ctx}/sys/loan/loan/manager?id=${loan.id}">设置客服人员</a>
				</shiro:hasPermission>
					<shiro:hasPermission name="sys:loan:loan:checkermanager">
						<a href="${ctx}/sys/loan/loan/checker?loanId=${loan.id}">符合产品的客户</a>

					</shiro:hasPermission>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>